package com.zzgc.modules.service.impl;

import com.zzgc.common.dao.StaticDistrictVisualizationDao;
import com.zzgc.common.entity.StaticDistrictVisualization;
import com.zzgc.modules.service.StaticDistrictVisualizationService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (StaticDistrictVisualization)表服务实现类
 *
 * @author makejava
 * @since 2023-05-19 09:08:57
 */
@Service("staticDistrictVisualizationService")
public class StaticDistrictVisualizationServiceImpl implements StaticDistrictVisualizationService {
    @Resource
    private StaticDistrictVisualizationDao staticDistrictVisualizationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StaticDistrictVisualization queryById(Long id) {
        return this.staticDistrictVisualizationDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param staticDistrictVisualization 筛选条件
     * @return 查询结果
     */
    @Override
    public List<StaticDistrictVisualization> queryByPage(StaticDistrictVisualization staticDistrictVisualization) {
        //long total = this.staticDistrictVisualizationDao.count(staticDistrictVisualization);
        return this.staticDistrictVisualizationDao.queryAllByLimit(staticDistrictVisualization);
    }

    /**
     * 根据年份，筛查次数，城市，计算数值的总和
     *
     * @return 查询结果
     */
    @Override
    public List<StaticDistrictVisualization> queryCountSum() {
        return this.staticDistrictVisualizationDao.queryCountSum();
    }

    /**
     * 查询总条数
     *
     * @param staticDistrictVisualization 筛选条件
     * @return 查询结果
     */
    @Override
    public Long count(StaticDistrictVisualization staticDistrictVisualization) {
        return this.staticDistrictVisualizationDao.count(staticDistrictVisualization);
    }

    /**
     * 新增数据
     *
     * @param staticDistrictVisualization 实例对象
     * @return 实例对象
     */
    @Override
    public StaticDistrictVisualization insert(StaticDistrictVisualization staticDistrictVisualization) {
        this.staticDistrictVisualizationDao.insert(staticDistrictVisualization);
        return staticDistrictVisualization;
    }

    /**
     * 修改数据
     *
     * @param staticDistrictVisualization 实例对象
     * @return 实例对象
     */
    @Override
    public StaticDistrictVisualization update(StaticDistrictVisualization staticDistrictVisualization) {
        this.staticDistrictVisualizationDao.update(staticDistrictVisualization);
        return this.queryById(staticDistrictVisualization.getId());
    }

    @Override
    public int restoreUnhealthy(Long id) {
        return this.staticDistrictVisualizationDao.restoreUnhealthy(id);
    }

    @Override
    public int restoreMyopiaRate(Long id) {
        return this.staticDistrictVisualizationDao.restoreMyopiaRate(id);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.staticDistrictVisualizationDao.deleteById(id) > 0;
    }
}
